package com.hzx.FilterUtils;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Objects;

@Configuration
public class KeyResolverConfig {

    /**
     * 从用户的角度限流
     */
    @Bean
    KeyResolver userKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("uId"));
    }

    /**
     * 从活动的角度限流
     */
    @Bean
    KeyResolver activityKeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("aId"));
    }
}
